import request from '@/utils/request'

// 查询生产请购单申请列表
export function listQgmMstr(query) {
  return request({
    url: '/purchase/qgmMstr/list',
    method: 'get',
    params: query,
  })
}
// 查询生产请购单可申请的物料
export function listSearchCld(query) {
  return request({
    url: '/purchase/qgmMstr/listSearchCld',
    method: 'get',
    params: query,
  })
}

// 查询生产请购单申请详细
export function getQgmMstr(qgmId) {
  return request({
    url: '/purchase/qgmMstr/' + qgmId,
    method: 'get',
  })
}
// 获取可分配的代用料
export function getAllotDyl(molId) {
  return request({
    url: '/purchase/qgmMstr/getAllotDyl/' + molId,
    method: 'get',
  })
}
//提交分配好的代用料
export function submitDyl(a) {
  return request({
    url: '/purchase/qgmMstr/submitDyl',
    method: 'post',
    data: a,
  })
}

// 新增生产请购单申请
export function addQgmMstr(data) {
  return request({
    url: '/purchase/qgmMstr',
    method: 'post',
    data: data,
  })
}
// 新增生产请购单子项数据
export function insertQgdDet(data) {
  return request({
    url: '/purchase/qgmMstr/insertQgdDet',
    method: 'post',
    data: data,
  })
}
// 根据主表 Id 查询Q详细数据
export function listQgdDet(qgmDjbh) {
  return request({
    url: '/purchase/qgmMstr/listQgdDet/' + qgmDjbh,
    method: 'get',
  })
}

// 修改生产请购单申请
export function updateQgmMstr(data) {
  return request({
    url: '/purchase/qgmMstr',
    method: 'put',
    data: data,
  })
}

// 删除生产请购单申请
export function delQgmMstr(qgmId) {
  return request({
    url: '/purchase/qgmMstr/' + qgmId,
    method: 'delete',
  })
}
// 删除生产请购单明细
export function delQgd(qgdId, qgdMolid) {
  return request({
    url: '/purchase/qgmMstr/delQgd/' + qgdId + '/' + qgdMolid,
    method: 'delete',
  })
}

// 导出生产请购单申请
export function exportQgmMstr(query) {
  return request({
    url: '/purchase/qgmMstr/export',
    method: 'get',
    params: query,
  })
}
// 删除生产请购单申请
export function allDylQgs(moeIds, qgmDjbhc) {
  return request({
    url: '/purchase/qgmMstr/allDylQgs/' + moeIds + '/' + qgmDjbhc,
    method: 'put',
  })
}

// 删除生产请购单申请
export function changeQgmZtbz(qgmDjbh, oldZtbz, newZtbz) {
  return request({
    url: '/purchase/qgmMstr/changeQgmZtbz/' + qgmDjbh + '/' + oldZtbz + '/' + newZtbz,
    method: 'put',
  })
}
export function getQgdCount(qgmDjbh) {
  return request({
    url: '/purchase/qgmMstr/getQgdCount/' + qgmDjbh,
    method: 'get',
  })
}

//审核单据
export function auditQgmMstr(qgmDjbhs) {
  return request({
    url: '/purchase/qgmMstr/auditQgmMstr/' + qgmDjbhs,
    method: 'post',
  })
}

//非计划审核单据
export function checkQgmMstr(qgmDjbhs) {
  return request({
    url: '/purchase/qgmMstr/checkQgmMstr/' + qgmDjbhs,
    method: 'post',
  })
}

//撤回单据
export function revokeQgmMstr(qgmDjbhs) {
  return request({
    url: '/purchase/qgmMstr/revokeQgmMstr/' + qgmDjbhs,
    method: 'put',
  })
}
//提交单据
export function submitQgmMstr(qgmDjbhs) {
  return request({
    url: '/purchase/qgmMstr/submitQgmMstr/' + qgmDjbhs,
    method: 'post',
  })
}

/**
 * @description: 撤回成型的按钮,接口
 * @param {*} id为molId
 * @return {*}
 */
export function rollbackOrder(id) {
  return request({
    url: `/produce/materialAdjust/rollbackOrder/${id}`,
    method: 'post',
  })
}

/**
 * @description: 采购预排接口
 * @param {*} id为molId
 * @return {*}
 */
export function getListWalkThrough(params) {
  return request({
    url: '/purchase/qgmMstr/listWalkThrough',
    method: 'get',
    params,
  })
}

/**
 * @description: 采购预排子表接口
 * @param { wtDjbh } 头表的请购单号(wt_djbh )
 * @return {*}
 */
export function getListChildWalkThrough(wtDjbh,wtWldm) {
  return request({
    url: `/purchase/qgmMstr/listWalkThroughList/${wtDjbh}/${wtWldm}`,
    method: 'get',
  })
}

// 导出上传模板
export function exportExampleWalkThrough() {
  return request({
    url: '/purchase/qgmMstr/exportExample',
    method: 'get',
  })
}
